public class test12 {
//递归求解汉诺塔问题

        public static void solveHanoi(int n, char source, char auxiliary, char target) {
            if (n == 1) {
                System.out.println("将圆盘 1 从 " + source + " 移动到 " + target);
                return;
            }
            solveHanoi(n - 1, source, target, auxiliary);
            System.out.println("将圆盘 " + n + " 从 " + source + " 移动到 " + target);
            solveHanoi(n - 1, auxiliary, source, target);
        }

        public static void main(String[] args) {
            int numDisks = 3; // 圆盘的数量
            solveHanoi(numDisks, 'A', 'B', 'C'); // A是源柱子，B是辅助柱子，C是目标柱子
        }

}
